package org.mobai.flow.utils;

import cn.hutool.extra.spring.SpringUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.camunda.bpm.model.bpmn.Bpmn;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.mobai.flow.pojo.bpmn.Node;
import org.mobai.flow.strategy.context.BpmnBuildContext;

public class BpmnUtil {
    static ObjectMapper objectMapper = new ObjectMapper();
        public static BpmnModelInstance convertToBpmn(String process) {
        BpmnBuildContext bpmnBuildContext = SpringUtil.getBean(BpmnBuildContext.class);

        BpmnModelInstance bpmnModelInstance;
        try {
            Node node = objectMapper.readValue(process, Node.class);
            bpmnModelInstance = bpmnBuildContext.buildBpmnModelInstance(node);
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }

            return bpmnModelInstance;
    }
}
